package spring.controller;


import java.rmi.RemoteException;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import auth.service.User;
public class LoginControler implements Controller{
	
	 /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());
    
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse responce)
    throws ServletException {
    	User u = (User) request.getSession().getAttribute("User");
    	u.login((String)request.getAttribute("login"),(String)request.getAttribute("password"));
    	request.getSession().setAttribute("User", u);
    	if((u.getAuth()==1)||u.getAuth()==2)
    		
    		
    	
    	return new ModelAndView(new RedirectView(getSuccessView()));
    	else
    		return new ModelAndView(new RedirectView(getFormView()));
    		

    }

	

	

}
